package org.ziegler.log.analysis;

import java.util.List;

import org.ziegler.log.analysis.core.FileUtils;

public class WhileRun {

    public static void main(String[] args) {
        int runCount = 0;
        while (!Thread.currentThread().isInterrupted()) {
            try {
                Thread.sleep(1000);

                System.out.println("[" + (++runCount) + "]running...");
            } catch (InterruptedException e) {
                // 线程终止，跳出循环
                FileUtils.appendWriteLines("test.log", List.of("InterruptedException线程终止，跳出循环"));
                System.out.println("InterruptedException线程终止，跳出循环 = " + e.getMessage());
                e.printStackTrace();
                break;
            }
        }

        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            System.out.println("Program terminate.");
            FileUtils.appendWriteLines("test.log", List.of("Program terminate."));
        }));

    }
}
